﻿package mortal.game.view.LineOffReward.data
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import Message.Public.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.signUp.data.*;
    import mortal.mvc.core.*;

    public class LineOffRewardCache extends Object
    {
        public var expData:int;
        public var showCopyArr:Array;
        public var showCopyObj:Object;
        public var lineOffInfo:SCompensationMsg;
        private var _hightestObj:Object;
        public var isOneKeyGet:Boolean = false;
        public var vipType:int = 33;

        public function LineOffRewardCache()
        {
            this._hightestObj = {};
            return;
        }// end function

        public function initInfoData(param1:SCompensationMsg) : void
        {
            this.lineOffInfo = param1;
            this.expData = this.lineOffInfo.offlineExp;
            this.setHightestOjb(param1.copysCompensation);
            this.checkExpShinkBtn();
            this.checkCopyShinkBtn();
            return;
        }// end function

        private function checkExpShinkBtn() : void
        {
            if (this.lineOffInfo == null)
            {
                return;
            }
            var _loc_1:* = this.lineOffInfo.offlineTime >= 1 * 3600;
            Cache.instance.signUp.hasRewardFlagObject[SignUpTabType.LineOffRewardExp] = _loc_1;
            Dispatcher.dispatchEvent(new DataEvent(EventName.SignUpCanGetReward, ["signUp", SignUpTabType.LineOffRewardExp, _loc_1]));
            return;
        }// end function

        private function checkCopyShinkBtn() : void
        {
            var _loc_3:SCopyCompensation = null;
            if (this.lineOffInfo == null)
            {
                return;
            }
            var _loc_1:Boolean = false;
            var _loc_2:int = 0;
            while (_loc_2 < this.lineOffInfo.copysCompensation.length)
            {
                
                _loc_3 = this.lineOffInfo.copysCompensation[_loc_2];
                if (_loc_3.count > 0)
                {
                    _loc_1 = true;
                    break;
                }
                _loc_2++;
            }
            Cache.instance.signUp.hasRewardFlagObject[SignUpTabType.LineOffRewardCopy] = _loc_1;
            Dispatcher.dispatchEvent(new DataEvent(EventName.SignUpCanGetReward, ["signUp", SignUpTabType.LineOffRewardCopy, _loc_1]));
            return;
        }// end function

        public function freshDate() : Array
        {
            if (this.lineOffInfo == null)
            {
                return [];
            }
            this.showCopyArr = this.reGetShowData(this.lineOffInfo.copysCompensation);
            return this.showCopyArr;
        }// end function

        public function updateExpData(param1:SPublicInt) : void
        {
            this.expData = param1.publicInt;
            this.lineOffInfo.offlineExp = param1.publicInt;
            this.lineOffInfo.offlineTime = 0;
            this.checkExpShinkBtn();
            return;
        }// end function

        public function updateCopyData(param1:SCopyCompensationMsg) : void
        {
            this.updateTimes(param1);
            this.checkCopyShinkBtn();
            return;
        }// end function

        public function updateTimes(param1:SCopyCompensationMsg) : void
        {
            var _loc_5:SCopyCompensation = null;
            var _loc_6:int = 0;
            var _loc_7:SCopyCompensation = null;
            var _loc_2:* = param1.copysCompensation;
            var _loc_3:* = this.lineOffInfo.copysCompensation;
            var _loc_4:int = 0;
            while (_loc_4 < _loc_2.length)
            {
                
                _loc_5 = _loc_2[_loc_4];
                _loc_6 = 0;
                while (_loc_6 < _loc_3.length)
                {
                    
                    _loc_7 = _loc_3[_loc_6];
                    if (_loc_7.copyCode == _loc_5.copyCode)
                    {
                        _loc_7.count = _loc_5.count;
                        break;
                    }
                    _loc_6++;
                }
                _loc_4++;
            }
            return;
        }// end function

        private function setHightestOjb(param1:Array) : void
        {
            var _loc_3:SCopyCompensation = null;
            var _loc_4:int = 0;
            var _loc_5:TOfflineCopyCompensate = null;
            var _loc_6:TCopy = null;
            var _loc_7:int = 0;
            var _loc_2:int = 0;
            while (_loc_2 < param1.length)
            {
                
                _loc_3 = param1[_loc_2];
                _loc_4 = 0;
                _loc_5 = LineOffRewardConfig.instance.getCfgById(_loc_3.copyCode);
                if (_loc_5 == null)
                {
                }
                else if (_loc_5.taskCode == 0)
                {
                    _loc_6 = CopyConfig.instance.getCopyInfoByCode(_loc_5.copyCode);
                    _loc_4 = _loc_6.group;
                    _loc_7 = int(this._hightestObj[_loc_4]);
                    if (_loc_6.enterMinLevel >= _loc_7)
                    {
                        this._hightestObj[_loc_6.group] = _loc_6.enterMinLevel;
                    }
                }
                _loc_2++;
            }
            return;
        }// end function

        private function reGetShowData(param1:Array) : Array
        {
            var _loc_4:SCopyCompensation = null;
            var _loc_5:TOfflineCopyCompensate = null;
            var _loc_6:TCopy = null;
            var _loc_7:int = 0;
            var _loc_2:Array = [];
            this.showCopyObj = {};
            var _loc_3:int = 0;
            while (_loc_3 < param1.length)
            {
                
                _loc_4 = param1[_loc_3];
                _loc_5 = LineOffRewardConfig.instance.getCfgById(_loc_4.copyCode);
                if (_loc_5.taskCode == 0)
                {
                    _loc_6 = CopyConfig.instance.getCopyInfoByCode(_loc_5.copyCode);
                    _loc_7 = int(this._hightestObj[_loc_6.group]);
                    if (_loc_6.enterMinLevel < _loc_7 && _loc_4.count == 0)
                    {
                        ;
                    }
                    else
                    {
                        _loc_2.push(_loc_4);
                        this.showCopyObj[_loc_4.copyCode] = _loc_4;
                    }
                }
                else
                {
                    _loc_2.push(_loc_4);
                    this.showCopyObj[_loc_4.copyCode] = _loc_4;
                }
                _loc_3++;
            }
            _loc_2.sort(this.sortCopy);
            return _loc_2;
        }// end function

        private function sortCopy(param1:SCopyCompensation, param2:SCopyCompensation) : int
        {
            if (param1.count > 0 && param2.count == 0)
            {
                return -1;
            }
            if (param1.count == 0 && param2.count > 0)
            {
                return 1;
            }
            if (param1.copyCode >= param2.copyCode)
            {
                return -1;
            }
            return 1;
        }// end function

    }
}
